package com.gator.desig_mode.translate;

import java.util.List;

/**
 * @author 何章怀晓 hezhanghuaixiao
 * @version V1.0
 * @desc 备忘录对象
 */
public class Memento {

  private String name;

  private float aggressivity;//攻击力

  private float defensivePower;//防御力

  //保存当前状态保存在集合中的索引

  private int index;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public float getAggressivity() {
    return aggressivity;
  }

  public void setAggressivity(float aggressivity) {
    this.aggressivity = aggressivity;
  }

  public float getDefensivePower() {
    return defensivePower;
  }

  public void setDefensivePower(float defensivePower) {
    this.defensivePower = defensivePower;
  }

  public int getIndex() {
    return index;
  }

  public void setIndex(int index) {
    this.index = index;
  }

  @Override
  public String toString() {
    return "Memento{" +
        "name='" + name + '\'' +
        ", aggressivity=" + aggressivity +
        ", defensivePower=" + defensivePower +
        ", index=" + index +
        '}';
  }
}


//备忘录管理
class Caretaker {


  //保存多个Memento
  private static List<Memento> list;

  public Caretaker(List<Memento> list) {
    this.list = list;
  }

  //添加备忘录到集合
  public int add(Memento memento) {
    list.add(memento);
    int index = list.indexOf(memento);
    //将插入的信息索引保存
    memento.setIndex(index);
    return index;
  }

  //获取
  public Memento get(int index) {
    if (index == 0) {
      list.get(0);
    }

    //获取上次状态，即当前下标的前一个下标
    return list.get(index - 1);
  }


}